package com.hjl.service.impl;

import com.hjl.dao.EmployeeDao;
import com.hjl.dao.impl.EmployeeDaoImpl;
import com.hjl.domain.Emp_Dept_Job_inf;
import com.hjl.domain.Employee_inf;
import com.hjl.domain.PageBean;
import com.hjl.service.EmployeeService;
import java.util.List;
import java.util.Map;

/**
 * 员工业务逻辑层实现类
 *
 * @author Lenovo
 * @version 1.0
 * @date 2021/10/8 20:35
 */
public class EmployeeServiceImpl implements EmployeeService {
    private EmployeeDao employeeDao = new EmployeeDaoImpl();

    /**
     * 分页查询
     *
     * @param currentPageString 当前页
     * @param rowsString        行数
     * @param condition         状态
     * @return com.hjl.domain.PageBean<com.hjl.domain.Emp_Dept_Job_inf>
     * @author Lenovo
     * @date 2021/10/8 20:41
     */
    @Override
    public PageBean<Emp_Dept_Job_inf> findEmployeeByPage(String currentPageString, String rowsString, Map<String, String[]> condition) {
        int currentPage = Integer.parseInt(currentPageString);
        int rows = Integer.parseInt(rowsString);
        int totalCount = employeeDao.findTotalCount(condition);
        int start = (currentPage - 1) * rows;
        List<Emp_Dept_Job_inf> list = employeeDao.findByPage(start, rows, condition);
        int totalPage = totalCount % rows == 0 ? totalCount / rows : (totalCount / rows + 1);
        //创建PageBean并放入数据，返回
        return new PageBean<>(totalCount, totalPage, list, currentPage, rows);
    }

    /**
     * 删除选中
     *
     * @param ids 选中的id
     * @author Lenovo
     * @date 2021/10/8 20:42
     */
    @Override
    public void delSelect(String[] ids) {
        if (ids != null && ids.length > 0) {
            for (String id : ids) {
                employeeDao.delEmployee(Integer.parseInt(id));
            }
        }
    }

    /**
     * 通过id查询
     *
     * @param id ID
     * @return com.hjl.domain.Emp_Dept_Job_inf
     * @author Lenovo
     * @date 2021/10/8 20:42
     */
    @Override
    public Emp_Dept_Job_inf findEmployeeById(String id) {
        return employeeDao.findEmployeeById(Integer.parseInt(id));
    }

    /**
     * 更新
     *
     * @param employee 员工对象
     * @author Lenovo
     * @date 2021/10/8 20:42
     */
    @Override
    public void updateEmployee(Employee_inf employee) {
        employeeDao.updateEmployee(employee);
    }

    /**
     * 添加
     *
     * @param employee 员工对象
     * @author Lenovo
     * @date 2021/10/8 20:42
     */
    @Override
    public void addEmployee(Employee_inf employee) {
        employeeDao.addEmployee(employee);
    }

    /**
     * 查询所有员工
     *
     * @return java.util.List<com.hjl.domain.Emp_Dept_Job_inf>
     * @author Lenovo
     * @date 2021/10/8 20:43
     */
    @Override
    public List<Emp_Dept_Job_inf> findAllEmployee() {
        return employeeDao.findAllEmployee();
    }

    /**
     * 查找所有身份证号
     *
     * @return java.util.List<java.lang.String>
     * @author Lenovo
     * @date 2021/10/8 20:43
     */
    @Override
    public List<String> findCardIds() {
        return employeeDao.findCardIds();
    }

    /**
     * 查找所有身份证号（排除自己）
     *
     * @param id ID
     * @return java.util.List<java.lang.String>
     * @author Lenovo
     * @date 2021/10/8 20:44
     */
    @Override
    public List<String> findCardIds(String id) {
        return employeeDao.findCardIds(id);
    }
}
